<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/pub/head_latest.inc"%>
<script type="text/javascript" src="${baseURL}/js/module/common_edit.js"></script>
<script src="${baseURL}/js/calculate.js" type="text/javascript"></script>
<script>
	 var calculate = new Calculate();
</script>
<title>${module.moduleName}</title>
<style type="text/css">
.l-checkboxlist{
	height: 30px;
	line-height: 27px;
}
.l-dialog-win .l-dialog-content {
    padding: 10px;
}

.l-panel{
	margin: 0 auto;
}

.l-panel-btn{
	float: right;
}

.l-panel-topbar {
    cursor: pointer;
}

.l-grid-totalsummary{
	background: none;
}

.l-grid-totalsummary td {
    line-height: 35px;
}
</style>
</head>
<body>
	<!-- 搜索表单 -->
	<div class="mainsearch" style="width: 98%">
		<div class="search-header">${report.moduleName}</div>
		<div class="searchbox">
			<%@ include file="../selector_form.jsp"%>
			<form id="formsearch" method="post">
				<input type="hidden" name="${report.module}list" id="${report.module}list"
					class="field" />
				<div class="selector-form"></div>
			</form>
		</div>
	</div>
	<!-- 报表打印区域 start -->
 	<iframe id="exportFrame" style="display:none" name="exportFrame" src="${baseURL}/report/complexreport/complexReport.do?csId=${drawForm.id}&rand=Math.rand()"></iframe>
 	<script>
 		var csId = '${drawForm.id}';
	 	function bulidFilterParams(){
	 		var data = getSelectorValue();
	 		data = {'searchParam':JSON.stringify(data)};
	 		return data;
		 }
		 	
		function FF_Print(){
			var json = bulidFilterParams();
			exportFrame.window.FF_Print(json);
		}
		
		function FF_ExportExcel(){
			var json = bulidFilterParams();
 			exportFrame.window.FF_ExportExcel(json);
		}
		
		function FF_ExportDoc(){
			var json = bulidFilterParams();
			exportFrame.window.FF_ExportDoc(json);
		}
		
		function FF_ExportPDF(){
			var json = bulidFilterParams();
			exportFrame.window.FF_ExportPDF(json);
		}
	</script>
	<!-- 报表打印区域 end -->
	
	<!-- 钻取的配置 start -->
	<script>
			function buildURLParams(json,url){
				var params = url+"&";
			var temp = "";
			for(var key in json){
				temp = key+"="+json[key];
				params += temp;
			}
			return params;
		}
	
		function FF_openDialog(data){
			$.ligerDialog({
				width:800,
				height:600,
				url:buildURLParams(data.json,data.url)
			});  
		}
		
		function FF_openTab(data){
 		 		parent.f_addTab(data.linkCode,data.linkName,buildURLParams(data.json,data.url));
		}
		
		function FF_openWindow(data){
			//设置弹窗大小
				var height = screen.height, // 用于计算弹出窗口的高度
					width  = screen.width - 80;  //用于计算弹出窗口的宽度
		  		window.open(buildURLParams(data.json,data.url),"newwindow","scrollbars=yes,height="+height+", width="+width+", top=0,left=60");
			}
	</script>
	<!-- 钻取的配置 end -->
	<script type="text/javascript">
  	 var win = parent || window;
  	 
 	var arr = [];
 	<c:if test="${drawForm.print}">
	 	arr.push({id : "print", name : "打印", clickEvent : FF_Print, icon : "a fa fa-print" ,type:"icon"});
 	</c:if>
 	<c:if test="${drawForm.excel}">
 		arr.push({id : "excel", name : "导出Excel", clickEvent : FF_ExportExcel,  icon : "a fa fa-file-excel-o" ,type:"icon"});
 	</c:if>
 	<c:if test="${drawForm.doc}">
		arr.push({id : "doc", name : "导出Word", clickEvent : FF_ExportDoc,  icon : "a fa fa-file-word-o" ,type:"icon"});
 	</c:if>
 	<c:if test="${drawForm.pdf}">
		arr.push({id : "pdf", name : "导出PDF", clickEvent : FF_ExportPDF, icon : "a fa fa-file-pdf-o" ,type:"icon"});
 	</c:if>
  	 
   	var report = {
   		grid:[],
   		options:{
   			newPage : 1,
   			url : null,
   			parms : null
   		},
   		set:function(key,value){
   			var r = this;
   			r.options[key] = value;
   		},
   		_setUrl:function(url){
   			var r = this;
   			r.options.url = url;
   			r.loadData();
   		},
   		loadData:function(){
   			var r = this;
   			$.ajax({
   				type:"post",
   	    		url:r.options.url,
   	    		data:r.options.parms,
   	    		beforeSend: function (){
	                LG.loading = true;
	                LG.showLoading('正在处理中...请稍候');
	            },
	            complete: function (){
	                LG.loading = false;	  
	                LG.hideLoading();
	            },
   	    		success:function(array){
  	    				for(var key in r.grid){
  	    					r.grid[key].options.columns = [];
	   	    				r.grid[key]._setColumns([]);
	   	    				r.grid[key].options.data = {};
	   	    				r.grid[key]._setData({});
	   	    				$("#maingrid"+key).hide();
  	    				}
  	    				var i = 0;
   	    			for(var key in array){
						var data = array[key];
						if(!(data && data.header && data.data && parseInt(data.data.Total)>0)){
    	    				continue;
    	    			}
    	    			var gridColumns = getColumns(data.header);
    	    			if(r.grid&&r.grid[key]){
   	    					r.grid[key].options.columns = gridColumns;
    	    				r.grid[key]._setColumns(gridColumns);
    	    				r.grid[key].options.data = data.data;
    	    				r.grid[key]._setData(data.data);
    	    				r.grid[key].options.title = data.title;
    	    				$(".l-panel-header-text",r.grid[key].element).html(data.title);
    	    				$("#maingrid"+key).show();
    	    			}else{
    	    				$("body").append("<div id='maingrid"+key+"'></div>");
    	    				var ligerGridData = { 
		      	    		          columns: gridColumns,data:data.data,
		      	    		          dataAction: 'local',
		      	    		          usePager:false,
		      	    		          width: '98%', height: 'auto',heightDiff:-10, checkbox: false,allowHideColumn:false,
		      	    		          pageSizeOptions:[${pageOptions}],rowHeight:30,rownumbers:true,isScroll:true
		      	    		  	};
    	    				<c:if test="${drawForm.print || drawForm.pdf || drawForm.doc || drawForm.excel}">
    	    				if(i==0){
    	    					ligerGridData.toolbar = {};
    	    				}
    	    				</c:if>
    	    				if(data.title){
    	    					ligerGridData.toolbar = {};
    	    					ligerGridData.title = data.title;
    	    				}
    	    				var grid = $("#maingrid"+key).ligerGrid(ligerGridData);
		      	    		if(i==0 && arr.length > 0){
		      	       	      	LG.createToolbarButton(grid, arr);
		      	          	}
		      	    		r.grid[key] = grid;
    	    			}
    	    			i++;
					}
   	    		}
   	    	});
   		}
   	};
   	
   	function getColumns(data){
       	 if(data){
       		 var columns = new Array();
           	 for(var key in data){
           		 var obj = null;
           		 if(data[key].child){
           			 var child = getColumns(data[key].child);
           			 obj = {display:data[key].display,columns:child};
           		 }else{
           			 obj = {display:data[key].display,name:data[key].name,width:'80',type:"text",align:"center",isSort : false};
           		 }
           		 if(data[key].totalSummary){
           			 obj.totalSummary = {type:data[key].totalSummary};
       			 }
       			 columns.push(obj);
           	 }
           	 return columns;
       	 }
       	 return null;
    }
   	
    $(".mainsearch>.search-header").click(function(){
   		 if($(".searchbox").is(":visible")){
   			 $(".searchbox").hide();
   		 }else{
   			 $(".searchbox").show();
   		 }
   	 });
    
     $(document).on("click",".l-panel-topbar",function(e){
    	 if($(e.target).hasClass("l-panel-topbarinner")){
    		 var obj = $(this).parent().find(".l-panel-bwarp");
    	 	 if($(obj).is(":visible")){
    			 $(obj).hide();
   		 	 }else{
   				 $(obj).show();
   		 	 }
    	 }
    });
	    
	</script>
	<script type="text/javascript">
	var exams = {};
	var sclass = {};
	var subject = {};
	var selectorData = JSON.parse('${report.selectorData}'||"[]",function(k,v){
		  if(v.indexOf&&v.indexOf('function')>-1){
		     return eval("(function(){return "+v+" })()");
		  }
		  return v;
	 });
	 var defaultData = JSON.parse('${report.defaultData}'||"[]",function(k,v){
		  if(v.indexOf&&v.indexOf('function')>-1){
		     return eval("(function(){return "+v+" })()");
		  }
		  return v;
	 });
	 initData($(".selector-form"),selectorData,defaultData,'${module.module}');	
	 
	//渲染选择器
  	 renderSelector(getDefaultSelector());
  	 for(var j = 0; j < defaultData.length; j++){
		 if(defaultData[j].id=="exam_id"){
			 $("li[selector-id='term_id']").hide();
			 $(".searchbox").hide();
			 break;
		 }
	 }
	 var searchCondition = JSON.parse('${report.searchCondition}'||"[]");
	 for (var i = 0; i < searchCondition.length; i++) {
		 var each = searchCondition[i];
		 if(each.data){
			 setSearchContainer(each.id, each.name, each.data);
		 }else if(each.url){
		  	 $.ajax({
				 type: "POST",
				 async : false,
				 url: baseURL + "/" + each.url,
				 success: function(data){
					 if(data){
						 setSearchContainer(each.id, each.name, data);
						 if(each.id == "term_id"){
							 renderNewSelector("term_id",data[data.length-1].id);
							 loadExam(data[data.length-1].id);
						 }
					 }
				 }
		 	 });
		 }
	}
	 
   initSearchGrid(report,'${baseURL}${report.listJSONURL}');
	 
   function beforeListExam(){
	  var termId = $("button[data-id='term_id']").attr("data-value");
	  if(exams && exams.hasOwnProperty(termId)){
	  	 setSearchContainer("exam_id", "考试", exams[termId]);
	  }else{
	  	 loadExam(termId);
	  }
   }
   
   function afterTermSelected(value){
	   loadExam(value);
   }
   
   function afterExamSelected(value){
	   loadClass(value);
	   return true;
   }
   
   function beforeListClass(value){
	   var examId = $("button[data-id='exam_id']").attr("data-value");
	   if(!examId){
		   examId = '${param.exam_id}';
	   }
	   if(sclass && sclass.hasOwnProperty(examId)){
	  	   for(var key in selectorData){
				if((selectorData[key].id).indexOf("class_id")!=-1){
					setSearchContainer(selectorData[key].id, "班级", sclass[examId]);
					break;
				}
		   }
	   }else{
		   loadClass(examId);
	   }
   }
   
   function beforeListSubject(value){
	   var examId = $("button[data-id='exam_id']").attr("data-value");
	   if(!examId){
		   examId = '${param.exam_id}';
	   }
	   if(subject && subject.hasOwnProperty(examId)){
	  	   for(var key in selectorData){
				if((selectorData[key].id).indexOf("subject_id")!=-1){
					setSearchContainer(selectorData[key].id, "科目", subject[examId]);
					break;
				}
		   }
	   }else{
		   loadSubject(examId);
	   }
   }
   
   function loadExam(termId){
  		var url = "/exam/exam/examlist/listJSONDataAll.do";
	    for (var i = 0; i < searchCondition.length; i++) {
			 var each = searchCondition[i];
			 if(each.id == "exam_id" && each.url){
				 url = each.url;
			 }
	    }
	 	$.ajax({
			type: "POST",
			async : false,
			url: baseURL + url,
			data:{termId:termId,isMine:0},
			success: function(data){
				if(data){
					setSearchContainer("exam_id", "考试", data);
					if(data.length>0){
						renderNewSelector("exam_id",data[data.length-1].id);
						exams[termId] = data;
						search();
					}
				}else{
					setSearchContainer("exam_id", "考试", []);
				}
			}
	 	});
   	}
   
   	function loadClass(examId){
	  	 $.ajax({
				type: "POST",
				async : false,
				url: baseURL + "/sclass/classlist/listJSONDataByExam.do",
				data:{examId:examId},
				success: function(data){
					if(data){
						sclass[examId] = data;
						for(var key in selectorData){
							if((selectorData[key].id).indexOf("class_id")!=-1){
								setSearchContainer(selectorData[key].id, "班级", data);
								break;
							}
						}
					}
				}
		 	});
	   }
   	
   	function loadSubject(examId){
   		var url = baseURL + "/exam/exam/examlist/listSubject.do";
   		for(var key in searchCondition){
   			if((searchCondition[key].id).indexOf("subject_id")!=-1){
   				url = baseURL + "/" + searchCondition[key].url;
   			}
   		}
	  	 $.ajax({
				type: "POST",
				async : false,
				url: url,
				data:{examId:examId},
				success: function(data){
					if(data){
						subject[examId] = data;
						for(var key in selectorData){
							if((selectorData[key].id).indexOf("subject_id")!=-1){
								setSearchContainer(selectorData[key].id, "科目", data);
								break;
							}
						}
					}
				}
		 	});
	   }
	</script>
</body>
</html>
